#include "mywidget.h"
#include "ui_mywidget.h"

MyWidget::MyWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MyWidget)
{
    ui->setupUi(this);

    auto vchangeFunc = [this](int value)
    {
        QSignalBlocker _blk1(ui->hscrooll);
        QSignalBlocker _blk2(ui->spinBox);
        QSignalBlocker _blk3(ui->vscrooll);
        QSignalBlocker _blk4(ui->dial);

        ui->hscrooll->setValue(value);
        ui->spinBox->setValue(value);
        ui->vscrooll->setValue(value);
        ui->dial->setValue(value);
    };


    connect(ui->hscrooll, &QScrollBar::valueChanged, vchangeFunc);
    //pre c++11
    typedef void (QSpinBox::*IFunc)(int);
    IFunc fptr = &QSpinBox::valueChanged;
    connect(ui->spinBox, fptr, vchangeFunc);

    //since c++11
    //connect(ui->spinBox, QOverload<int>::of(&QSpinBox::valueChanged), vchangeFunc);

    //since c++14
    //connect(ui->spinBox, qOverload<int>(&QSpinBox::valueChanged), vchangeFunc);
    connect(ui->vscrooll, &QScrollBar::valueChanged, vchangeFunc);
    connect(ui->dial, &QDial::valueChanged, vchangeFunc);
}

MyWidget::~MyWidget()
{
    delete ui;
}
